//package com.ycrlkj.android.modulespublic.common.net.transformer;
//
//import android.util.Log;
//import androidx.annotation.NonNull;
//import com.ycrlkj.android.modulespublic.common.net.exception.ApiException;
//import com.ycrlkj.android.modulespublic.common.net.response.MResponse;
//import io.reactivex.Observable;
//import io.reactivex.ObservableSource;
//import io.reactivex.ObservableTransformer;
//import io.reactivex.android.schedulers.AndroidSchedulers;
//import io.reactivex.functions.Function;
//import io.reactivex.schedulers.Schedulers;
//
//public class CommonTransformer<T> implements ObservableTransformer<MResponse<T>, T> {
//
//    public static <U> CommonTransformer<U> obtain() {
//        return new CommonTransformer<>();
//    }
//
//    @NonNull
//    @Override
//    public ObservableSource<T> apply(Observable<MResponse<T>> upstream) {
//        return upstream
//                //错误处理
//                .onErrorResumeNext(new Function<Throwable, ObservableSource<? extends MResponse<T>>>() {
//                    @Override
//                    public ObservableSource<? extends MResponse<T>> apply(Throwable throwable) throws Exception {
//                        Log.e("ming", "请求出错");
//
//                        // 出现异常后统一处理
//                        return Observable.error(ApiException.exception2ApiException(throwable));
//                    }
//                })
//                //json转换
//                .flatMap(new Function<MResponse<T>, ObservableSource<T>>() {
//                    @Override
//                    public ObservableSource<T> apply(@NonNull MResponse<T> response) throws Exception {
//
//                        Log.e("ming", "请求解析中");
//
//                        return new ResponseDataHandler<T>(response).doWith();
//                    }
//                })
//                //切到io线程
//                .subscribeOn(Schedulers.io())
//                //切到主线程
//                .observeOn(AndroidSchedulers.mainThread());
//    }
//}
